window.addEvent('load',function()
{
    var form=$('Form_Password');
    var button=$('Submit_Password');
    form.addEvent('submit',function()
    {
        var oldPassword=$('OldPassword');
        var newPassword=$('NewPassword');
        var confirmPassword=$('ConfirmPassword');

        if(oldPassword.value=='')
        {
            malert('请填写旧密码');
            oldPassword.focus();
            return false;
        }

        if(newPassword.value=='')
        {
            malert('请填写新密码');
            newPassword.focus();
            return false;
        }

        if(confirmPassword.value=='')
        {
            malert('请确认新密码');
            confirmPassword.focus();
            return false;
        }

        if(confirmPassword.value!=newPassword.value)
        {
            malert('两次输入密码不一致，请重新填写');
            confirmPassword.select();
            return false;
        }

        var myRequest = new Request
        ({
            url:form.action,
            method:'post',
            onRequest:function()
            {
                button.disabled=true;
            },
            onSuccess: function($responseText)
            {
                if($responseText=='Success')
                {
                    parent.$('EditPassword').retrieve('instance').close();
                    malert('密码修改成功');                    
                }
                else if($responseText=='NotLogined')
                {
                    alert('登录超时，请重新登录。');
                    window.location='login.php';
                }
                else if($responseText=='PasswordWrong')
                {
                    malert('旧密码输入不正确，请重新填写');
                    oldPassword.select();
                }
                else
                {
                    document.write($responseText);
                }
                button.disabled=false;
            },
            onFailure: function()
            {
                malert('请求错误');
            }
        }).send('OldPassword='+oldPassword.value+'&NewPassword='+newPassword.value+'&ConfirmPassword='+confirmPassword.value);
        
        return false;
    });
});